import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
# 初始化浏览器（确保已配置好ChromeDriver）
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.implicitly_wait(10)  # 全局隐式等待


# 访问目标URL
target_url = "http://192.168.66.162:20080/login?redirect=%2Findex"
driver.get(target_url)
print(f"成功访问URL：{target_url}")

# 使用XPath定位用户名输入框（替换为你的实际XPath）
# 等待元素可点击（最多等待15秒）
username_input = WebDriverWait(driver, 15).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="app"]/div/div[1]/form/div[1]/div/div/input'))
)
print("用户名输入框已加载完成")
username_input.send_keys("bonss_medical_admin")  # 替换为实际账号


password_input = WebDriverWait(driver, 15).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="app"]/div/div[1]/form/div[2]/div/div/input'))
)
password_input.send_keys("admin123..")

# 示例：定位登录按钮（假设XPath为下方，需替换为实际值）
login_button = WebDriverWait(driver, 15).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="app"]/div/div[1]/form/div[4]/div/button'))
)
login_button.click()
print("点击登录按钮")
time.sleep(4)




